package com.jason.exp.api.proto;

import com.google.common.collect.Lists;
import com.jason.exp.entity.Region;
import com.jason.exp.utils.BeanMapper;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.io.Serializable;
import java.util.List;

/**
 * Created by fuyongde on 2016/8/31.
 */
public class RegionDto implements Serializable {
    private Integer id;
    private Integer parentId;
    private String name;
    private Integer level;
    private List<RegionDto> childs;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public List<RegionDto> getChilds() {
        return childs;
    }

    public void setChilds(List<RegionDto> childs) {
        this.childs = childs;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    /**
     * 将Region转化为RegionDto
     *
     * @param region
     * @param regionList
     * @return
     */
    public static RegionDto fromRegion(Region region, List<Region> regionList) {
        RegionDto regionDto = BeanMapper.map(region, RegionDto.class);
        List<RegionDto> regionDtos = Lists.newArrayList();
        regionList.forEach((temp) -> {
            regionDtos.add(BeanMapper.map(temp, RegionDto.class));
        });
        regionDto.setChilds(regionDtos);
        return regionDto;
    }

}
